package com.ruoyi.business.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.business.domain.Shop;
import com.ruoyi.business.domain.ShopDto;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.ShopMapper;
import com.ruoyi.business.service.ShopService;

/**

 * 商铺信息Service业务层处理

 *

 * @author ruoyi

 * @date 2025-06-09
 */
@Service
public class ShopServiceImpl implements ShopService
{
    @Autowired
    private ShopMapper tbShopMapper;

    /**

     * 查询商铺信息
     *
     * @param id 商铺信息主键
     * @return 商铺信息
     */
    @Override
    public Shop selectTbShopById(String id)
    {
        return tbShopMapper.selectTbShopById(id);
    }

    /**

     * 查询商铺信息列表
     *
     * @param shop 商铺信息
     * @return 商铺信息
     */
    @Override
    public List<ShopDto> selectTbShopList(Shop shop,Long userId)
    {
       List<ShopDto> tbShopList = new ArrayList<>();
       List<Shop> list = tbShopMapper.selectTbShopList(shop,userId);
       for (Shop shopOne : list) {
           ShopDto tbShopDto = new ShopDto();
           String type_id = shopOne.getTypeId();
           String typeName = tbShopMapper.selectTbShopTypeById(type_id);
           tbShopDto.setTypeName(typeName);
           tbShopDto.setId(shopOne.getId());
           tbShopDto.setName(shopOne.getName());
           tbShopDto.setTypeId(shopOne.getTypeId());
           tbShopDto.setImages(shopOne.getImages());
           tbShopDto.setArea(shopOne.getArea());
           tbShopDto.setAddress(shopOne.getAddress());
           tbShopDto.setAvgPrice(shopOne.getAvgPrice());
           tbShopDto.setSold(shopOne.getSold());
           tbShopDto.setComments(shopOne.getComments());
           tbShopDto.setScore(shopOne.getScore());
           tbShopDto.setOpenHours(shopOne.getOpenHours());
           tbShopDto.setStatus(shopOne.getStatus());
           tbShopDto.setIsDeleted(shopOne.getIsDeleted());
           tbShopList.add(tbShopDto);
       }
        return tbShopList;
    }

    /**

     * 新增商铺信息
     *
     * @param shop 商铺信息
     * @return 结果
     */
    @Override
    public int insertTbShop(Shop shop,Long userId)
    {
        shop.setCreateTime(DateUtils.getNowDate());
        return tbShopMapper.insertTbShop(shop,userId);
    }

    /**

     * 修改商铺信息
     *
     * @param shop 商铺信息
     * @return 结果
     */
    @Override
    public int updateTbShop(Shop shop)
    {
        shop.setUpdateTime(DateUtils.getNowDate());
        return tbShopMapper.updateTbShop(shop);
    }

    /**

     * 批量删除商铺信息
     *
     * @param ids 需要删除的商铺信息主键
     * @return 结果
     */
    @Override
    public int deleteTbShopByIds(Long[] ids)
    {
        return tbShopMapper.deleteTbShopByIds(ids);
    }

    /**

     * 删除商铺信息信息
     *
     * @param id 商铺信息主键
     * @return 结果
     */
    @Override
    public int deleteTbShopById(String id)
    {
        return tbShopMapper.deleteTbShopById(id);
    }

    @Override
    public List<Shop> getAllShop(Long userId) {
       return tbShopMapper.getAllShop(userId);
    }


}